//定义学生store
import {defineStore} from 'pinia'
import {ref} from 'vue'

export const useStudentStore = defineStore('student',()=>{
    //定义状态的内容

    //1.响应式变量
    const studentInfo = ref({})

    //2.定义一个函数,修改学生信息的值
    const setStudentInfo = (newStudentInfo)=>{
        studentInfo.value = newStudentInfo
    }

    //3.函数,移除学生信息的值
    const removeStudentInfo = ()=>{
        studentInfo.value = {}
    }

    //4.获取学生姓名
    const getStudentName = () => {
        return studentInfo.value.realName || '学生'
    }

    //5.获取学生学号
    const getStudentId = () => {
        return studentInfo.value.studentId || ''
    }

    //6.获取学生学院
    const getStudentCollege = () => {
        return studentInfo.value.college || ''
    }

    return {
        studentInfo,
        setStudentInfo,
        removeStudentInfo,
        getStudentName,
        getStudentId,
        getStudentCollege
    }
},{
    persist: true
}); 